package com.mopoba.app;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.mrpoid.shequ2.R;


/**
 * 宫格适配器
 * 
 * @author Yichou 2013-9-22
 *
 */
public abstract class BaseGridAdapter extends BaseAdapter {
	protected Context mContext;
	protected LayoutInflater mInflater;

	
	public BaseGridAdapter(Context context) {
		mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mContext = context;
	}
	
	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}
	
	final int[] COLORS = {
			0xFF3366,
			0xFF6600,
			0x009933,
			0xCC33FF,
			0x00CCFF,
			0x99CC00,
			0xFFCC00
		};

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		
		if(convertView == null) {
			View v = mInflater.inflate(R.layout.item_plugin, null);
			
			TextView textView = (TextView) v.findViewById(R.id.textView1);
			textView.setText("正在开发");
			
			int c = (COLORS[position % COLORS.length]);
			textView.setBackgroundColor(0x80000000 | (c&0x00ffffff));
			
			convertView = v;
			
			holder = new ViewHolder();
			holder.mTextView = textView;
			
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		String title = getItemTitle(position);
		if(title != null) {
			holder.mTextView.setText(title);
		}
		
		Bitmap bmp = getItemImage(position);
		if(bmp != null) {
//			holder.mTextView.setY(y)
		}
		
		return convertView;
	}
	
	private final class ViewHolder {
		TextView mTextView;
	}
	
	protected abstract Bitmap getItemImage(int index);

	protected abstract Bitmap getItemBg(int index);

	protected abstract String getItemTitle(int index);
}